import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

async function main() {
  // 清除现有数据
  await prisma.region.deleteMany()

  // 添加示例数据
  const regions = [
    // 省级
    { code: '11', name: '北京市', level: 1, orderNum: 1 },
    { code: '31', name: '上海市', level: 1, orderNum: 2 },
    
    // 市级
    { code: '1101', name: '市辖区', level: 2, parentCode: '11', orderNum: 1 },
    { code: '3101', name: '市辖区', level: 2, parentCode: '31', orderNum: 1 },
    
    // 区级
    { code: '110101', name: '东城区', level: 3, parentCode: '1101', orderNum: 1 },
    { code: '110102', name: '西城区', level: 3, parentCode: '1101', orderNum: 2 },
    { code: '310101', name: '黄浦区', level: 3, parentCode: '3101', orderNum: 1 },
    
    // 街道级
    { code: '110101001', name: '东华门街道', level: 4, parentCode: '110101', orderNum: 1 },
    { code: '110101002', name: '景山街道', level: 4, parentCode: '110101', orderNum: 2 },
    
    // 社区级
    { code: '110101001001', name: '多福巷社区', level: 5, parentCode: '110101001', orderNum: 1 },
    { code: '110101001002', name: '东厂社区', level: 5, parentCode: '110101001', orderNum: 2 },
  ]

  for (const region of regions) {
    await prisma.region.create({
      data: region
    })
  }
}

main()
  .catch((e) => {
    console.error(e)
    process.exit(1)
  })
  .finally(async () => {
    await prisma.$disconnect()
  }) 